package com.example.langchain4j12chatrag01.controller;

import com.example.langchain4j12chatrag01.service.ChatAssistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wwl
 * 日期  2025/10/13 16:41
 * 版本 1.0
 * 描述 :
 */
@RestController
@Slf4j
public class RAGController {
    @Resource
    InMemoryEmbeddingStore<TextSegment> embeddingStore;
    @Resource
    ChatAssistant chatAssistant;
    @GetMapping("/testAdd")
    public String testAdd(@RequestParam(value = "prompt", defaultValue = "你是谁?") String prompt){
       Document document =  FileSystemDocumentLoader.loadDocument("C:\\Users\\Administrator\\Desktop\\个人\\2020年下半年全员信息安全考试培训材料.pdf");
        EmbeddingStoreIngestor.ingest(document,embeddingStore);
        String result = chatAssistant.chat(prompt);
        System.out.println(result);
        return result;
    }
}
